package com.wyw.hemerocallis.stream;

import com.alibaba.fastjson.JSON;
import com.wyw.hemerocallis.vo.WywMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.cloud.stream.messaging.Sink;

/**
 * 使用默认的信道实现消息的接收
 *
 * @author Mr Wu    yewen.wu.china@gmail.com
 * <p>
 * Update History:
 * Author        Time            Content
 */
@Slf4j
@EnableBinding(Sink.class)
public class DefaultReceiveService {

    /**
     * 使用默认的输入信道接收消息
     */
    @StreamListener(Sink.INPUT)
    public void receiveMessage(Object payload) {
        log.info("in DefaultReceiveService consume message start");
        WywMessage wywMessage =
                JSON.parseObject(payload.toString(), WywMessage.class);
        //消费消息
        log.info("in DefaultReceiveService consume message success: [{}]",
                JSON.toJSONString(wywMessage));
    }
}
